package com.share.thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @desc:
 * @author:caifan
 * @date:2021/2/25
 */
public class CountDownLatchDemo {

    public static void main(String[] args) throws Exception {
        CountDownLatch countDownLatch = new CountDownLatch(2);
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        for (int i = 0; i < 2; i++) {
            executorService.execute(() -> {
                worker(countDownLatch);
            });
        }
        countDownLatch.await();
        executorService.shutdown();
    }

    private static void worker(CountDownLatch countDownLatch) {
        for (int i = 0; i <=5; i++) {
            System.out.println(i);
        }
        countDownLatch.countDown();
    }
}
